package com.example.streamer.util;

import com.sun.jna.Pointer;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
import java.util.ArrayList;
import java.util.List;

public class WindowUtils {
    public static class WindowInfo {
        public HWND hwnd;
        public String title;
        public WindowInfo(HWND hwnd, String title) {
            this.hwnd = hwnd;
            this.title = title;
        }
    }

    public static List<WindowInfo> listWindows() {
        List<WindowInfo> result = new ArrayList<>();
        User32.INSTANCE.EnumWindows((hWnd, data) -> {
            if (User32.INSTANCE.IsWindowVisible(hWnd)) {
                char[] buffer = new char[512];
                User32.INSTANCE.GetWindowText(hWnd, buffer, 512);
                String title = Native.toString(buffer).trim();
                if (!title.isEmpty()) {
                    result.add(new WindowInfo(hWnd, title));
                }
            }
            return true;
        }, Pointer.NULL);
        return result;
    }
} 